<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>切换图片</title>
	</head>
	<body>
		<input type="button" value="下一张" onclick="next()"/>
		<input type="button" value="上一张" onclick="prev()" /><br />
		<img src="1.jpg" id="d1"/>
		<script>
		var i = 1;
		var next = function(){
			i++;
			if(i>=6){
				i = 5;
				alert("已经是最后一张了！");
			}else{
				d1.src = i + ".jpg";
			}
		};
		var prev = function(){
			if(i<=1){
				alert("已经是第一张了！");
			}else{
				i--;
				d1.src = i + ".jpg";
			}
		}
		</script>
	</body>
</html>
